<template>
  <div>
    <Card>

      <Table
        ref="tableLkyApplyPage"
        :data="tableData"
        :columns="columns"
        @on-selection-change="onSelectionChange"
        @on-sort-change="onSortChange"
      />
	  <Add v-model="isOpenAddPage" :UploadLkyDocumentTableManage="uploadLkyDocumentTableManage" />
      <div style="margin: 10px;overflow: hidden">
        <div style="float: right;">
          <Page
            :total="total"
            :current="current"
            :page-size="pageSize"
            @on-page-size-change="changePageSize"
            @on-change="changePage"
            :show-total="true"
            show-sizer
          ></Page>
        </div>
      </div>

    </Card>
  </div>

</template>

<script>

import { list } from '@/api/lky/lkyApplyPage'

import { createFormObj , getToken , createModelObj } from '@/libs/util'
 // 学院查询、专业查询


import { queryAll } from '@/api/lky/lkyCollege'
import { queryAllM } from '@/api/lky/lkyMajor'
// import { updateS } from '@/api/lky/lkyApplyAdmin'
import Add from './add.vue'
import Edit from './edit.vue'

export default {
  name: 'LkyApplyPage',
  components: {
    Add,
    Edit
  },
  data () {
    return {
      collegeList: [],
      coid: '',
      majorList: [],
      formLkyApply: {
        id: '',
		aid:'',
        fife_name: '',
        times: '',
        count: '',
        creation_time: '',
        staute: '',
        mid: ''
      },
      columns: [
       
        { key: 'file_name', title: '表名', sortable: true },
        { key: 'creation_time', title: '申请时间', sortable: true },
        { key: 'remark_info', title: '申请理由', sortable: true },
        { key: 'staute', title: '是否批准', sortable: true, render: (h, params) => h('span', this.transFromStatue(params.row.staute)) },
        {
          title: '操作',
          key: 'action',
          width: 250,
          align: 'center',
          render: (h, params) => {
            return h('div', [
              h(
                'Button',
                {
                  props: {
                    type: 'error',
                    size: 'small',
                    disabled: (params.row.staute == '0' || params.row.staute == '2' )
                  },
                  style: {
                    marginRight: '5px',
										
                  },
                  on: {
                    click: () => {
					  // var obj = {}
					  // obj.id = params.row.aid
					  // updateS(Object.assign({}, createModelObj(obj, 'lkyApplyRecord'))).then(res => {
					  // })
						this.getLkyApplyList(this.current, this.pageSize)
                        this.uploadLkyDocumentTableManage = params.row
                        this.handleOpenPage('upload')
					  
                    }
                  }
                },
                '上传'
              )
            ])
          }
        }
      ],
      tableData: [],
      total: 0,
      current: 1,
      pageSize: 10,
      isOpenAddPage: false,
      isOpenEditPage: false,
	  uploadLkyDocumentTableManage: null ,
      editLkyApply: {},
      selection: []
    }
  },
  methods: {
    onOpenChangeCollege () {
      queryAll().then(res => {
        this.collegeList = res.data
      })
    },
    transFromStatue (val) {
      if (val === 0) {
        return '未批准'
      } else if (val === 1) {
        return '已批准'
      } else if (val === 2 ){
		  return '已上传'
	  }
    },
    onOpenChangeMajor (coid) {
      queryAllM({ 'coid': this.coid }).then(res => {
        this.majorList = JSON.parse(JSON.stringify(res.data))
      })
    },
    handleOpenPage (name) {
      if (name == 'upload') this.isOpenAddPage = true
    },
    addLkyApplyPage (row) {
      this.tableData.push(row)
      this.getLkyApplyList(this.current, this.pageSize)
    },
    updateLkyApply (row) {
      this.$set(this.tableData, row._index, row)
    },
    batchDelete () {
      this.$Modal.confirm({
        title: '提示',
        content: '<p>确定删除吗?</p>',
        onOk: () => {
          if (this.selection.length > 0) {
            let ids = ''
            for (var i = 0; i < this.selection.length; i++) {
              ids += ',' + this.selection[i].id
            }
            batchDelete({ ids: ids }).then(res => {
              for (var i = 0; i < this.selection.length; i++) {
                this.tableData = this.tableData.filter(
                  item => item.id !== this.selection[i].id
                )
              }
            })
          } else {
            this.$Message.error('未选中记录!')
          }
        },
        onCancel: () => {}
      })
    },
    getLkyApplyList (current, pageSize, paras) {
      let para = { pageNumber: current, pageSize: pageSize }
      Object.assign(para, { uid: getToken() })
      if (paras) Object.assign(para, paras)

      // 后台的持久层框架 是？？ mybatis? // 这是 jfinal aaaa
      // 没用过这个呀，可以再controllor  里面选择走不同的 查询// 这个里面没有
			Object.assign(para,{uid:getToken()})

      list(this.handleRequestParams(para)).then(res => {
        this.tableData = res.list
        this.current = parseInt(res.pageNumber)
        this.pageSize = parseInt(res.pageSize)
        this.total = parseInt(res.totalRow)
      })
    },
    // 往申请页面
    handleRequestParams (para) {
      Object.assign(para, createFormObj(this.formLkyApply, 'lkyApply'))
      return para
    },
    exportExcel () {
      this.$refs.tableLkyApply.exportCsv({
        filename: `table-${new Date().valueOf()}.csv`
      })
    },
    changePage (pageNumber) {
      this.getLkyApplyList(pageNumber, this.pageSize)
    },
    changePageSize (pageSize) {
      this.getLkyApplyList(this.current, pageSize)
    },
    remove (index) {
      this.data6.splice(index, 1)
    },
    onSelectionChange (selection) {
      this.selection = selection
    },
    onSortChange (obj) {
      if (obj.order === 'normal') {
        this.getLkyApplyList(1, this.pageSize)
      } else {
        this.getLkyApplyList(1, this.pageSize, {
          field: obj.key,
          order: obj.order
        })
      }
    }
  },
  mounted () {
	this.uid =getToken(),
    this.getLkyApplyList(this.current, this.pageSize)
  }
}
</script>
<style>
</style>
